package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Homeclass;
import com.ruoyi.system.service.IHomeclassService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商城页面的商品列模块Controller
 * 
 * @author ruoyi
 * @date 2022-12-08
 */
@Controller
@RequestMapping("/system/homeclass")
public class HomeclassController extends BaseController
{
    private String prefix = "system/homeclass";

    @Autowired
    private IHomeclassService homeclassService;

    @RequiresPermissions("system:homeclass:view")
    @GetMapping()
    public String homeclass()
    {
        return prefix + "/homeclass";
    }

    /**
     * 查询商城页面的商品列模块列表
     */
    @RequiresPermissions("system:homeclass:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Homeclass homeclass)
    {
        startPage();
        List<Homeclass> list = homeclassService.selectHomeclassList(homeclass);
        return getDataTable(list);
    }

    /**
     * 导出商城页面的商品列模块列表
     */
    @RequiresPermissions("system:homeclass:export")
    @Log(title = "商城页面的商品列模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Homeclass homeclass)
    {
        List<Homeclass> list = homeclassService.selectHomeclassList(homeclass);
        ExcelUtil<Homeclass> util = new ExcelUtil<Homeclass>(Homeclass.class);
        return util.exportExcel(list, "商城页面的商品列模块数据");
    }

    /**
     * 新增商城页面的商品列模块
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商城页面的商品列模块
     */
    @RequiresPermissions("system:homeclass:add")
    @Log(title = "商城页面的商品列模块", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Homeclass homeclass)
    {
        return toAjax(homeclassService.insertHomeclass(homeclass));
    }

    /**
     * 修改商城页面的商品列模块
     */
    @RequiresPermissions("system:homeclass:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Homeclass homeclass = homeclassService.selectHomeclassById(id);
        mmap.put("homeclass", homeclass);
        return prefix + "/edit";
    }

    /**
     * 修改保存商城页面的商品列模块
     */
    @RequiresPermissions("system:homeclass:edit")
    @Log(title = "商城页面的商品列模块", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Homeclass homeclass)
    {
        return toAjax(homeclassService.updateHomeclass(homeclass));
    }

    /**
     * 删除商城页面的商品列模块
     */
    @RequiresPermissions("system:homeclass:remove")
    @Log(title = "商城页面的商品列模块", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(homeclassService.deleteHomeclassByIds(ids));
    }
}
